package cn.enilu.flash.mobile.controller;

import cn.enilu.flash.bean.core.BussinessLog;
import cn.enilu.flash.bean.entity.cms.Article;
import cn.enilu.flash.bean.entity.cms.Banner;
import cn.enilu.flash.bean.enumeration.Permission;
import cn.enilu.flash.bean.vo.front.Rets;
import cn.enilu.flash.bean.vo.query.SearchFilter;
import cn.enilu.flash.service.cms.ArticleService;
import cn.enilu.flash.service.cms.BannerService;
import cn.enilu.flash.utils.JsonUtil;
import cn.enilu.flash.utils.StringUtil;
import cn.enilu.flash.web.controller.BaseController;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * banner管理
 */
@RestController
@RequestMapping("/banner")
public class BannerMgrController extends BaseController {
    private final String INDEX = "index";
    @Autowired
    private BannerService bannerService;
    @Autowired
    private ArticleService articleService;

    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public Object list() {
        SearchFilter filter  =  SearchFilter.build("type", INDEX);
        List<Banner> list = bannerService.queryAll(filter, Sort.by(Sort.Direction.ASC,"sort"));
        return Rets.success(list);
    }

    @RequestMapping(value="getArticleById",method = RequestMethod.POST)
    public Object getArticleById(@RequestParam(value = "id") Long id){
        if(null == id){
            Rets.failure("id不能为空");
        }
        Article article = articleService.get(id);
        if(null == article){
            Rets.failure("文章不存在");
        }
        return Rets.success(article);
    }
}
